package com.carleasoft.mps.forum.business.answer.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.forum.business.answer.bean.ForumComment;
import com.carleasoft.mps.forum.business.answer.bean.ForumPlate;
import com.carleasoft.mps.forum.business.answer.bean.po.ForumPlatePo;
import com.carleasoft.mps.forum.business.answer.bean.po.ForumUserPo;
import com.carleasoft.mps.forum.business.answer.service.ForumPlateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zang
 * @since 2023-05-09
 */
@RestController
@RequestMapping("/forumPlate")
public class ForumPlateController {

    @Autowired
    private ForumPlateService forumPlateService;

    /**
     * @author zang
     * @desc 板块新增
     * @date 2023-05-19
     */
    @PostMapping("/saveForumPlate")
    public R saveForumPlate(@RequestBody ForumPlate forumPlate) {
        forumPlateService.saveForumPlate(forumPlate);
        return R.ok();
    }
    
    /**
     * @author zang
     * @desc 板块修改
     * @date 2023-05-19
     */
    @PostMapping("/updateForumPlate")
    public R updateForumPlate(@RequestBody ForumPlate forumPlate) {
        forumPlateService.updateForumPlate(forumPlate);
        return R.ok();
    }

    /**
     * @author zang
     * @desc 分页查询板块
     * @date 2023-05-19
     */
    @PostMapping("/selForumPlate")
    public R selForumPlate(@RequestBody ForumPlatePo forumPlatePo) {
        Page page = new Page(forumPlatePo.getCurrent(), forumPlatePo.getSize());
        Page<ForumPlate> res = forumPlateService.selForumPlate(page,forumPlatePo);
        return R.ok(res);
    }
    
    /**
     * @author zang
     * @desc 模块详情
     * @date 2023-05-19
     */
    @PostMapping("/detailForumPlate")
    public R detailForumPlate(@RequestBody ForumPlatePo forumPlatePo) {
        ForumPlate res = forumPlateService.detailForumPlate(forumPlatePo);
        return R.ok(res);
    }

    /**
     * @author zang
     * @desc 发布状态修改
     * @date 2023-05-19
     */
    @PostMapping("/updateForumPlateApprove")
    public R updateForumPlateApprove(@RequestBody ForumPlatePo forumPlatePo) {
        forumPlateService.updateForumPlateApprove(forumPlatePo);
        return R.ok();
    }
    /**
     * @author zang
     * @desc 停用状态修改
     * @date 2023-05-19
     */
    @PostMapping("/updateForumPlateStatus")
    public R updateForumPlateStatus(@RequestBody ForumPlatePo forumPlatePo) {
        forumPlateService.updateForumPlateStatus(forumPlatePo);
        return R.ok();
    }

    /**
     * @author zang
     * @desc 批量删除(逻辑删除)
     * @date 2023-05-19
     */
    @PostMapping("/deleteForumPlate")
    public R deleteForumPlate(@RequestBody ForumPlatePo forumPlatePo) {
        forumPlateService.deleteForumPlate(forumPlatePo);
        return R.ok();
    }
    
    /**
     * @author zang
     * @desc 查询板块信息
     * @date 2023-06-15
     */
    @PostMapping("/selAllForumPlate")
    public R selAllForumPlate() {
        List<ForumPlate> res = forumPlateService.list(new QueryWrapper<ForumPlate>().eq("IS_USED", 1)
                .eq("IS_DELETE", 0));
        return R.ok(res);
    }

    /**
     * @author zang
     * @desc 分页查询
     * @date 2023-06-19
     */
    @PostMapping("/pageMinePlate")
    public R pageMinePlate(@RequestBody ForumUserPo forumUserPo) {
        Page page = new Page(forumUserPo.getCurrent(), forumUserPo.getSize());
        Page<ForumPlate> res = forumPlateService.pageMinePlate(page,forumUserPo);
        return R.ok(res);
    }
}

